<template>
  <div>
    <a-card :bordered="false">
      <div style="margin: 0 0 10px 0">
        <a-space size="small" />
      </div>

      <a-table
        :row-selection="rowSelection"
        :columns="columns"
        :data-source="data"
        :pagination="pagination"
        :loading="loading"
        @change="handleTableChange"
        bordered
      />
    </a-card>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { findActivityListPage } from '@/api/activiti/processHistory'
import { formatDate, formatCtsDate } from '@/utils/date.js'
const columns = [
  // {
  //   title: "活动ID",
  //   dataIndex: "activityId",
  //   sorter: true,
  //   // ellipsis: true,
  // },
  {
    title: '活动名称',
    dataIndex: 'activityName',
    // ellipsis: true,
  },
  {
    title: '活动类型',
    dataIndex: 'activityType',
    // ellipsis: true,
  },
  {
    title: '代理人员',
    dataIndex: 'assigneeName',
    customRender: (text, row, index) => {
      return text
    },
  },
  {
    title: '审批意见',
    dataIndex: 'comment_msg',
    // ellipsis: true,
  },
  {
    title: '审批时间',
    dataIndex: 'comment_time',
    customRender: (text, row, index) => {
      if (text == undefined) {
        return ''
      } else {
        return formatDate(text)
      }
    },
  },
  // {
  //   title: "执行流ID",
  //   dataIndex: "executionId",
  //   // ellipsis: true,
  // },
  // {
  //   title: "任务ID",
  //   dataIndex: "taskId",
  //   // ellipsis: true,
  // },
  // {
  //   title: "流程实例ID",
  //   dataIndex: "processInstanceId",
  //   // ellipsis: true,
  // },
  // {
  //   title: "流程定义ID",
  //   dataIndex: "processDefinitionId",
  //   // ellipsis: true,
  // },
  {
    title: '开始时间',
    dataIndex: 'startTime',
    customRender: (text, row, index) => {
      return formatDate(text)
    },
  },
  {
    title: '结束时间',
    dataIndex: 'endTime',
    customRender: (text, row, index) => {
      if (text == '' || text == null) {
        return '任务未结束'
      } else if (text == '模块已删除') {
        return '模块已删除'
      } else {
        return formatDate(text)
      }
    },
  },
]

export default {
  // 声明当前子组件接收父组件传递的属性
  props: {
    record: {
      type: Object,
      default: null,
    },
  },
  data () {
    return {
      data: [],
      pagination: {},
      loading: false,
      columns,
      selectedRows: [],
      queryParam: {},
    }
  },
  components: {},
  computed: {
    rowSelection () {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRows = selectedRows
          console.log(
            `selectedRowKeys: ${selectedRowKeys}`,
            'selectedRows: ',
            selectedRows,
          )
        },
      }
    },
  },
  mounted () {
    this.fetch({ pageSize: 10 })
  },
  methods: {
    handleTableChange (pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
      this.pagination = pager
      this.fetch({
        pageSize: pagination.pageSize,
        pageNum: pagination.current,
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
      })
    },
    fetch (params = {}) {
      this.loading = true
      findActivityListPage({
        ...params,
        processInstanceId: this.record.processInstanceId,
      }).then((response) => {
        const pagination = { ...this.pagination }
        // Read total count from server
        // pagination.total = data.totalCount;
        pagination.total = response.data.count
        this.loading = false
        this.data = response.data.data
        this.pagination = pagination
      })
    },
  },
}
</script>
<style scoped>
</style>
